import 'package:flutter_admin/utils/utils.dart';

class ProductStockorder {

  String? id;
  String? stockorderno;
  String? orderdate;
  String? productId;
  String? productCode;
  String? productName;
  String? productDesc;
  num? orderqty;
  String? remark;
  String? createUid;
  String? createName;
  String? createDate;
  String? createDateStart;
  String? createDateEnd;
  String? writeUid;
  String? writeDate;
  String? isSupplement;
  List<Object?>? processList;

  ProductStockorder({
    this.id,
    this.stockorderno,
    this.orderdate,
    this.productId,
    this.productCode,
    this.productName,
    this.productDesc,
    this.orderqty,
    this.remark,
    this.createUid,
    this.createName,
    this.createDate,
    this.createDateStart,
    this.createDateEnd,
    this.writeUid,
    this.writeDate,
    this.isSupplement,
    this.processList,
  });

  ProductStockorder copyWith({
    String? id,
    String? stockorderno,
    String? orderdate,
    String? productId,
    num? orderqty,
    String? remark,
    String? createUid,
    String? createDate,
    String? writeUid,
    String? writeDate,
  }) {
    return new ProductStockorder(
      id: id ?? this.id,
      stockorderno: stockorderno ?? this.stockorderno,
      orderdate: orderdate ?? this.orderdate,
      productId: productId ?? this.productId,
      orderqty: orderqty ?? this.orderqty,
      remark: remark ?? this.remark,
      createUid: createUid ?? this.createUid,
      createDate: createDate ?? this.createDate,
      writeUid: writeUid ?? this.writeUid,
      writeDate: writeDate ?? this.writeDate,
    );
  }

  @override
  String toString() {
    return '''ProductStockorder{
      id: id,
      stockorderno: stockorderno,
      orderdate: orderdate,
      productId: productId,
      orderqty: orderqty,
      remark: remark,
      createUid: createUid,
      createDate: createDate,
      writeUid: writeUid,
      writeDate: writeDate,
    }''';
  }

  @override
  bool operator ==(Object other) => identical(this, other) || (
      other is ProductStockorder &&
          runtimeType == other.runtimeType
          && id== other.id
          && stockorderno== other.stockorderno
          && orderdate== other.orderdate
          && productId== other.productId
          && orderqty== other.orderqty
          && remark== other.remark
          && createUid== other.createUid
          && createDate== other.createDate
          && writeUid== other.writeUid
          && writeDate== other.writeDate
   );


  factory ProductStockorder.fromMap(Map<String, dynamic> map) {
    return new ProductStockorder(
      id: map['id']!=false?map['id'].toString() as String?:"",
      stockorderno: map['stockorderno']!=false?map['stockorderno'].toString() as String?:"",
      orderdate: map['orderdate']!=false?Utils.getDate(date: map['orderdate']).toString() as String?:"",
      productId: map['product_id']['id']!=false?map['product_id']['id'].toString() as String?:"",
      productCode: map['product_id']['default_code']!=false?map['product_id']['default_code'].toString() as String?:"",
      productName: map['product_id']['name']!=false?map['product_id']['name'].toString() as String?:"",
      productDesc: map['product_id']['description']!=false?map['product_id']['description'].toString() as String?:"",
      orderqty: map['orderqty']!=false?map['orderqty']:0,
      remark: map['remark']!=false?map['remark'].toString() as String?:"",
      createUid: map['create_uid'][0]!=false?map['create_uid'][0].toString() as String?:"",
      createName: map['create_uid'][1]!=false?map['create_uid'][1].toString() as String?:"",
      createDate: map['create_date']!=false?map['create_date'].toString() as String?:"",
      writeUid: map['write_uid']!=false?map['write_uid'].toString() as String?:"",
      writeDate: map['write_date']!=false?map['write_date'].toString() as String?:"",
      isSupplement: map['is_supplement']!=false?map['is_supplement'].toString() as String?:"",
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'stockorderno': this.stockorderno,
      'orderdate': this.orderdate,
      'productId': this.productId,
      'orderqty': this.orderqty,
      'remark': this.remark,
      'createUid': this.createUid,
      'createDate': this.createDate,
      'writeUid': this.writeUid,
      'writeDate': this.writeDate,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if(this.stockorderno!=null&&this.stockorderno!='')['stockorderno','like',"%${this.stockorderno}%"],
      if(this.productCode!=null&&this.productCode!='')['product_id.default_code','like',"%${this.productCode}%"],
      if(this.productName!=null&&this.productName!='')['product_id.name','like','%${this.productName}%'],
      if(this.createDateStart!=null&&this.createDateStart!='')['create_date','>=',Utils.timeUTC(this.createDateStart!+' 00:00:00',isToBeijing: false)],
      if(this.createDateEnd!=null&&this.createDateEnd!='')['create_date','<=',Utils.timeUTC(this.createDateEnd!+' 23:59:59',isToBeijing: false)],
      if(this.isSupplement!=null&&this.isSupplement!='')['is_supplement','=',this.isSupplement],
    ];
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'stockorderno': this.stockorderno,
      'orderdate': this.orderdate,
      'product_id': this.productId,
      'orderqty': this.orderqty,
      'remark': this.remark,
      'create_uid': this.createUid,
      'create_date': this.createDate,
      'write_uid': this.writeUid,
      'write_date': this.writeDate,
      'is_supplement': this.isSupplement,
      'product_stockorderprocess':this.processList!.map((e) =>
        {"stockorderno":this.stockorderno,"process_id":e}
       ).toList()
    } as Map<String, dynamic>;
  }

//</editor-fold>

}